new Vue({
    el:'#app',
    data:{
        list:[
            {
                id:1,
                name:'华为',
                price:6188,
                count:1
            },
            {
                id:2,
                name:'小米',
                price:5188,
                count:2
            },
            {
                id:3,
                name:'中兴',
                price:5999,
                count:5
            }
        ]
    },
    computed:{
        totalPrice:function(){
            var total = 0;
            this.list.forEach(function(item){
                total += item.price * item.count;
            });
            return total.toString().replace(/\B(?=(\d{3})+$)/g,',');
           //return total;
        }
    },
    methods:{
        handleReduce:function(index){
            if(this.list[index].count === 1) return;
            this.list[index].count--;
        },
        handleAdd:function(index){
            this.list[index].count++;
        },
        handleRemove:function(index){
            this.list.splice(index,1);
        }
    }
});